home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / mx / RCS / mx.c,v < prev    next >
Encoding:
Text File  |  1990-11-11  |  27.7 KB  |  1,350 lines

  1. head     1.27;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.27
  10. date     90.11.11.11.52.00;  author ouster;  state Exp;
  11. branches ;
  12. next     1.26;
  13.  
  14. 1.26
  15. date     90.03.22.15.35.30;  author ouster;  state Exp;
  16. branches ;
  17. next     1.25;
  18.  
  19. 1.25
  20. date     90.01.29.10.04.24;  author ouster;  state Exp;
  21. branches ;
  22. next     1.24;
  23.  
  24. 1.24
  25. date     89.08.19.13.01.15;  author ouster;  state Exp;
  26. branches ;
  27. next     1.23;
  28.  
  29. 1.23
  30. date     89.07.10.10.14.43;  author ouster;  state Exp;
  31. branches ;
  32. next     1.22;
  33.  
  34. 1.22
  35. date     89.06.08.15.20.30;  author ouster;  state Exp;
  36. branches ;
  37. next     1.21;
  38.  
  39. 1.21
  40. date     89.06.05.12.16.40;  author shirriff;  state Exp;
  41. branches ;
  42. next     1.20;
  43.  
  44. 1.20
  45. date     89.05.19.10.35.30;  author ouster;  state Exp;
  46. branches ;
  47. next     1.19;
  48.  
  49. 1.19
  50. date     89.05.19.10.33.13;  author ouster;  state Exp;
  51. branches ;
  52. next     1.18;
  53.  
  54. 1.18
  55. date     89.01.07.12.20.31;  author ouster;  state Exp;
  56. branches ;
  57. next     1.17;
  58.  
  59. 1.17
  60. date     88.12.23.14.55.16;  author ouster;  state Exp;
  61. branches ;
  62. next     1.16;
  63.  
  64. 1.16
  65. date     88.10.03.09.23.14;  author ouster;  state Exp;
  66. branches ;
  67. next     1.15;
  68.  
  69. 1.15
  70. date     88.08.31.08.19.32;  author ouster;  state Exp;
  71. branches ;
  72. next     1.14;
  73.  
  74. 1.14
  75. date     88.08.20.15.49.50;  author ouster;  state Exp;
  76. branches ;
  77. next     1.13;
  78.  
  79. 1.13
  80. date     88.07.18.13.45.14;  author ouster;  state Exp;
  81. branches ;
  82. next     1.12;
  83.  
  84. 1.12
  85. date     88.04.20.17.23.41;  author ouster;  state Exp;
  86. branches ;
  87. next     1.11;
  88.  
  89. 1.11
  90. date     88.04.01.12.58.45;  author ouster;  state Exp;
  91. branches ;
  92. next     1.10;
  93.  
  94. 1.10
  95. date     88.03.31.09.21.44;  author ouster;  state Exp;
  96. branches ;
  97. next     1.9;
  98.  
  99. 1.9
  100. date     88.03.16.17.30.43;  author ouster;  state Exp;
  101. branches ;
  102. next     1.8;
  103.  
  104. 1.8
  105. date     88.01.07.09.14.20;  author ouster;  state Exp;
  106. branches ;
  107. next     1.7;
  108.  
  109. 1.7
  110. date     88.01.05.19.22.22;  author nelson;  state Exp;
  111. branches ;
  112. next     1.6;
  113.  
  114. 1.6
  115. date     88.01.04.15.30.04;  author ouster;  state Exp;
  116. branches ;
  117. next     1.5;
  118.  
  119. 1.5
  120. date     88.01.03.15.21.42;  author ouster;  state Exp;
  121. branches ;
  122. next     1.4;
  123.  
  124. 1.4
  125. date     87.11.28.13.25.43;  author ouster;  state Exp;
  126. branches ;
  127. next     1.3;
  128.  
  129. 1.3
  130. date     87.10.23.14.16.32;  author deboor;  state Exp;
  131. branches ;
  132. next     1.2;
  133.  
  134. 1.2
  135. date     87.08.24.10.55.33;  author ouster;  state Exp;
  136. branches ;
  137. next     1.1;
  138.  
  139. 1.1
  140. date     87.08.21.10.33.58;  author ouster;  state Exp;
  141. branches ;
  142. next     ;
  143.  
  144.  
  145. desc
  146. @@
  147.  
  148.  
  149. 1.27
  150. log
  151. @Reduce # of signals for which handlers are declared:  handlers make
  152. it hard to track bugs.
  153. @
  154. text
  155. @/* 
  156.  * mx.c --
  157.  *
  158.  *    This file contains the top-level routines for "mx", a mouse-based
  159.  *    editor that runs on top of the X window system and uses the Sx
  160.  *    library package.
  161.  *
  162.  * Copyright (C) 1986, 1987, 1988 Regents of the University of California.
  163.  * Permission to use, copy, modify, and distribute this
  164.  * software and its documentation for any purpose and without
  165.  * fee is hereby granted, provided that the above copyright
  166.  * notice appear in all copies.  The University of California
  167.  * makes no representations about the suitability of this
  168.  * software for any purpose.  It is provided "as is" without
  169.  * express or implied warranty.
  170.  */
  171.  
  172. #ifndef lint
  173. static char rcsid[] = "$Header: /sprite/src/cmds/mx/RCS/mx.c,v 1.26 90/03/22 15:35:30 ouster Exp Locker: ouster $ SPRITE (Berkeley)";
  174. #endif not lint
  175.  
  176. #include <X11/Xlib.h>
  177. #include <X11/Xutil.h>
  178. #define Time SpriteTime
  179. #include <ctype.h>
  180. #include <errno.h>
  181. #include <signal.h>
  182. #include <stdio.h>
  183. #include <stdlib.h>
  184. #include <string.h>
  185. #include "mxInt.h"
  186.  
  187. /*
  188.  * Forward references to other procedures defined in this file:
  189.  */
  190.  
  191. static void        MainSignalProc();
  192.  
  193. /*
  194.  *----------------------------------------------------------------------
  195.  *
  196.  * main --
  197.  *
  198.  *    The main program for mx.  Initialize, load file, create window,
  199.  *    and loop processing events.
  200.  *
  201.  * Results:
  202.  *    None.
  203.  *
  204.  * Side effects:
  205.  *    Almost anything can happen.  Depends on commands that user types.
  206.  *
  207.  *----------------------------------------------------------------------
  208.  */
  209.  
  210. main(argc, argv)
  211.     int argc;            /* Count of command-line arguments. */
  212.     char **argv;        /* Array of strings containing args. */
  213. {
  214.     int detach = 0;
  215.     int signalPid = 0;
  216.     int i, put;
  217.     char *p;
  218.     Tcl_Interp *interp;        /* Initial interpreter used for error
  219.                  * reporting before there's a window open
  220.                  * within an interpreter of its own to use. */
  221.  
  222.     /*
  223.      * If running under Sprite, tell the memory allocator to be paranoid
  224.      * about freeing the same block twice.
  225.      */
  226.  
  227. #ifdef sprite
  228.     extern int memAllowFreeingFree;
  229.     memAllowFreeingFree = 0;
  230. #endif
  231.  
  232.     /*
  233.      *--------------------------------------------------------------
  234.      * Parse some of the command line arguments, leaving many others
  235.      * to get parsed by Mx_OpenCmd.
  236.      *--------------------------------------------------------------
  237.      */
  238.  
  239.     p = rindex(argv[0], '/');
  240.     if (p == NULL) {
  241.     p = argv[0];
  242.     } else {
  243.     p++;
  244.     }
  245.     if (strcmp(p, "mxsync") == 0) {
  246.     detach = 0;
  247.     } else {
  248.     detach = 1;
  249.     }
  250.     interp = Tcl_CreateInterp();
  251.     for (i = 1, put = 1; i < argc; i++) {
  252.     if (strcmp(argv[i], "-D") == 0) {
  253.         detach = 0;
  254.     } else if (strcmp(argv[i], "-s") == 0) {
  255.         i++;
  256.         if (i >= argc) {
  257.         fprintf(stderr,
  258.             "Mx: argument for \"%s\" switch missing.\n",
  259.             argv[i-1]);
  260.         exit(1);
  261.         }
  262.         signalPid = atoi(argv[i]);
  263.     } else {
  264.         argv[put] = argv[i];
  265.         put++;
  266.     }
  267.     }
  268.     argc = put;
  269.     if (detach) {
  270.     Proc_Detach(0);
  271.     }
  272.     Sx_SetErrorHandler();
  273.     (void) signal(SIGINT, MainSignalProc);
  274.     (void) signal(SIGQUIT, MainSignalProc);
  275.     (void) signal(SIGTERM, MainSignalProc);
  276.  
  277.     /*
  278.      *------------------------------------------------------
  279.      * Create the (first) window.
  280.      *------------------------------------------------------
  281.      */
  282.  
  283.     if (Mx_OpenCmd((MxWindow *) NULL, interp, argc, argv) != TCL_OK) {
  284.     fprintf(stderr, "Mx quitting: %s\n", interp->result);
  285.     exit(1);
  286.     }
  287.  
  288.     /*
  289.      *--------------------------------------------
  290.      * Enter a loop reading and processing events.
  291.      *--------------------------------------------
  292.      */
  293.  
  294.     while (1) {
  295.     XEvent event;
  296.     XNextEvent(mx_Display, &event);
  297.  
  298.     /*
  299.      * Part of Mike's hack.  Remove when Mike's gone.
  300.      */
  301.      
  302.     if ((signalPid != 0) && (event.type == Expose)) {
  303.         kill(signalPid, SIGINT);
  304.         signalPid = 0;
  305.     }
  306.     Sx_HandleEvent(&event);
  307.     if (mx_FileCount == 0) {
  308.         exit(0);
  309.     }
  310.     Mx_Update();
  311.     }
  312. }
  313.  
  314. /*
  315.  *----------------------------------------------------------------------
  316.  *
  317.  * MainSignalProc --
  318.  *
  319.  *    Invoked in response to fatal signals.
  320.  *
  321.  * Results:
  322.  *    None.
  323.  *
  324.  * Side effects:
  325.  *    Clean up Mx windows, then exit.
  326.  *
  327.  *----------------------------------------------------------------------
  328.  */
  329.  
  330.     /* ARGSUSED */
  331.  
  332. static void
  333. MainSignalProc(sigNum, sigCode)
  334.     int sigNum;            /* Signal number (major class). */
  335.     int sigCode;        /* Signal code (minor class). */
  336. {
  337.     static struct sigvec action = {SIG_DFL, 0, 0};
  338.     struct sigvec old;
  339.  
  340.     sigvec(sigNum, &action, &old);
  341.     Mx_Cleanup();
  342.     kill(getpid(), sigNum);
  343. }
  344. @
  345.  
  346.  
  347. 1.26
  348. log
  349. @Added "mxsync" option to avoid detaching.
  350. @
  351. text
  352. @d19 1
  353. a19 1
  354. static char rcsid[] = "$Header: /sprite/src/cmds/mx/RCS/mx.c,v 1.25 90/01/29 10:04:24 ouster Exp Locker: ouster $ SPRITE (Berkeley)";
  355. a120 5
  356.     (void) signal(SIGFPE, MainSignalProc);
  357.     (void) signal(SIGILL, MainSignalProc);
  358.     (void) signal(SIGBUS, MainSignalProc);
  359.     (void) signal(SIGSEGV, MainSignalProc);
  360.     (void) signal(SIGSYS, MainSignalProc);
  361. @
  362.  
  363.  
  364. 1.25
  365. log
  366. @Don't include proc.h anymore.
  367. @
  368. text
  369. @d19 1
  370. a19 1
  371. static char rcsid[] = "$Header: /sprite/src/cmds/mx/RCS/mx.c,v 1.24 89/08/19 13:01:15 ouster Exp Locker: ouster $ SPRITE (Berkeley)";
  372. d63 1
  373. d84 12
  374. a95 2
  375.     
  376.     detach = 1;
  377. @
  378.  
  379.  
  380. 1.24
  381. log
  382. @Turn on duplicate-free checks.
  383. @
  384. text
  385. @d19 1
  386. a19 1
  387. static char rcsid[] = "$Header: /a/newcmds/mx/RCS/mx.c,v 1.23 89/07/10 10:14:43 ouster Exp Locker: ouster $ SPRITE (Berkeley)";
  388. a26 1
  389. #include <proc.h>
  390. @
  391.  
  392.  
  393. 1.23
  394. log
  395. @Forgot to initialize signalPid.
  396. @
  397. text
  398. @d19 1
  399. a19 1
  400. static char rcsid[] = "$Header: /a/newcmds/mx/RCS/mx.c,v 1.22 89/06/08 15:20:30 ouster Exp Locker: shirriff $ SPRITE (Berkeley)";
  401. d67 10
  402. @
  403.  
  404.  
  405. 1.22
  406. log
  407. @Moved almost everything out of this file and into Mx_OpenCmd.
  408. @
  409. text
  410. @d19 1
  411. a19 1
  412. static char rcsid[] = "$Header: /a/newcmds/mx/RCS/mx.c,v 1.21 89/06/05 12:16:40 shirriff Exp $ SPRITE (Berkeley)";
  413. d62 2
  414. a63 3
  415.     Window window;
  416.     int i, put, signalPid;
  417.     MxWindow *mxwPtr;
  418. a82 1
  419.         missingArg:
  420. a124 1
  421.     mainLoop:
  422. @
  423.  
  424.  
  425. 1.21
  426. log
  427. @Added timestamp reading when opening first file.
  428. @
  429. text
  430. @d19 1
  431. a19 1
  432. static char rcsid[] = "$Header: /a/newcmds/mx/RCS/mx.c,v 1.20 89/05/19 10:35:30 ouster Exp Locker: shirriff $ SPRITE (Berkeley)";
  433. a34 6
  434.  * Connection to X server:
  435.  */
  436.  
  437. Display *display;
  438.  
  439. /*
  440. d38 1
  441. a38 2
  442. static unsigned long    MainGetColor();
  443. static int        MainSignalProc();
  444. d61 1
  445. a61 3
  446.     Mx_WindowInfo info;
  447.     char *geometry, *fg, *bg, *fn, *displayName, *searchString;
  448.     char *border, *sbFg, *sbBg, *sbEl, *titleFg, *titleBg, *titleStripe;
  449. d63 1
  450. a63 1
  451.     int i, lineNumber;
  452. a64 4
  453.     struct sigvec old, action;
  454.     int debug;
  455.     int signalPid;        /* Special hack for Mike. */
  456.     int exitValue = 0;
  457. d70 4
  458. a73 3
  459.      *------------------------------
  460.      * Parse command line arguments.
  461.      *------------------------------
  462. d76 1
  463. a76 5
  464.     geometry = fg = bg = fn = displayName = searchString = NULL;
  465.     border = sbFg = sbBg = sbEl = titleFg = titleBg = titleStripe = NULL;
  466.     info.name = NULL;
  467.     lineNumber = -1;
  468.     debug = 0;
  469. d78 4
  470. a81 4
  471.     for (i = 1; i < argc; i++) {
  472.     if (*argv[i] == '=') {
  473.         geometry = argv[i];
  474.     } else if (strcmp(argv[i], "-fn") == 0) {
  475. d90 1
  476. a90 111
  477.         fn = argv[i];
  478.     } else if (strcmp(argv[i], "-fg") == 0) {
  479.         i++;
  480.         if (i >= argc) {
  481.         goto missingArg;
  482.         }
  483.         fg = argv[i];
  484.     } else if (strcmp(argv[i], "-bg") == 0) {
  485.         i++;
  486.         if (i >= argc) {
  487.         goto missingArg;
  488.         }
  489.         bg = argv[i];
  490.     } else if (strcmp(argv[i], "-bd") == 0) {
  491.         i++;
  492.         if (i >= argc) {
  493.         goto missingArg;
  494.         }
  495.         border = argv[i];
  496.     } else if (strcmp(argv[i], "-sf") == 0) {
  497.         i++;
  498.         if (i >= argc) {
  499.         goto missingArg;
  500.         }
  501.         sbFg = argv[i];
  502.     } else if (strcmp(argv[i], "-sb") == 0) {
  503.         i++;
  504.         if (i >= argc) {
  505.         goto missingArg;
  506.         }
  507.         sbBg = argv[i];
  508.     } else if (strcmp(argv[i], "-se") == 0) {
  509.         i++;
  510.         if (i >= argc) {
  511.         goto missingArg;
  512.         }
  513.         sbEl = argv[i];
  514.     } else if (strcmp(argv[i], "-tf") == 0) {
  515.         i++;
  516.         if (i >= argc) {
  517.         goto missingArg;
  518.         }
  519.         titleFg = argv[i];
  520.     } else if (strcmp(argv[i], "-tb") == 0) {
  521.         i++;
  522.         if (i >= argc) {
  523.         goto missingArg;
  524.         }
  525.         titleBg = argv[i];
  526.     } else if (strcmp(argv[i], "-ts") == 0) {
  527.         i++;
  528.         if (i >= argc) {
  529.         goto missingArg;
  530.         }
  531.         titleStripe = argv[i];
  532.     } else if (strcmp(argv[i], "-t") == 0) {
  533.          int result;
  534.         
  535.         i++;
  536.         if (i >= argc) {
  537.         goto missingArg;
  538.         }
  539.         Tcl_Return(interp, (char *) NULL, TCL_STATIC);
  540.         result = Mx_GetTag(argv[i], (char *) NULL, &info.name,
  541.             &searchString, interp);
  542.         if (result != TCL_OK) {
  543.         fprintf(stderr, "%s\n", interp->result);
  544.         exit(1);
  545.         }
  546.         lineNumber = -1;
  547.     } else if (strcmp(argv[i], "-D") == 0) {
  548.         debug = 1;
  549.     } else if (strcmp(argv[i], "-s") == 0) {
  550.         /*
  551.          * This is a special temporary hack to help Mike Nelson's
  552.          * instrumentaion package.  Signal the given pid's family
  553.          * when the window appears on the screen.
  554.          */
  555.  
  556.         i++;
  557.         if (i >= argc) {
  558.         goto missingArg;
  559.         }
  560.         sscanf(argv[i], "%d", &signalPid);
  561.     } else if (argv[i][0] == '-') {
  562.         fprintf(stderr, "Mx: switch \"%s\" isn't legal.\n",
  563.             argv[i]);
  564.         exit(1);
  565.     } else if (index(argv[i], ':') != NULL) {
  566.         displayName = argv[i];
  567.     } else if (argv[i][0] == '+') {
  568.         if (argv[i][1] == 0) {
  569.         lineNumber = -2;
  570.         searchString = NULL;
  571.         } else if (!isdigit(argv[i][1])) {
  572.         searchString = argv[i] + 1;
  573.         if (*searchString == '/') {
  574.             searchString++;
  575.         }
  576.         lineNumber = -1;
  577.         } else { 
  578.         char *result;
  579.         lineNumber = strtol(argv[i] + 1, &result, 10);
  580.         if ((result == (argv[i] + 1)) || (*result != 0)
  581.             || (lineNumber < 1)) {
  582.             fprintf(stderr,
  583.                 "Mx: \"%s\" is a bad line number.\n", argv[i]);
  584.             exit(1);
  585.         }
  586.         searchString = NULL;
  587.         }
  588. d92 2
  589. a93 1
  590.         info.name = argv[i];
  591. d96 2
  592. a97 1
  593.     if (!debug) {
  594. a99 14
  595.  
  596.     display = XOpenDisplay(displayName);
  597.     if (display == NULL) {
  598.     if (displayName == NULL) {
  599.         fprintf(stderr, "Mx couldn't open the display.\n");
  600.         fprintf(stderr,
  601.             "Is your DISPLAY environment variable set?\n");
  602.     } else {
  603.         fprintf(stderr, "Mx couldn't open display %s.\n",
  604.         displayName);
  605.     }
  606.     exit(1);
  607.     }
  608.     /* XSynchronize(display, True); */
  609. d101 8
  610. a108 29
  611.     if (geometry == NULL) {
  612.     geometry = XGetDefault(display, "mx", "geometry");
  613.     }
  614.  
  615.     /*
  616.      * If no file name is given, start up on the first tutorial.  In this
  617.      * case, also provide a default geometry if none was given.
  618.      */
  619.  
  620.     if (info.name == NULL) {
  621.     static char tutName[100];
  622.     sprintf(tutName, "%.80s/%s", MXLIBDIR, "tutorial1");
  623.     info.name = tutName;
  624.     if (geometry == NULL) {
  625.         geometry = "=80x50+0+0";
  626.     }
  627.     }
  628.  
  629.     action.sv_handler = MainSignalProc;
  630.     action.sv_mask = 0;
  631.     action.sv_onstack = 0;
  632.     sigvec(SIGINT, &action, &old);
  633.     sigvec(SIGQUIT, &action, &old);
  634.     sigvec(SIGFPE, &action, &old);
  635.     sigvec(SIGILL, &action, &old);
  636.     sigvec(SIGBUS, &action, &old);
  637.     sigvec(SIGSEGV, &action, &old);
  638.     sigvec(SIGSYS, &action, &old);
  639.     sigvec(SIGTERM, &action, &old);
  640. d112 1
  641. a112 1
  642.      * Create the (first) window, and set up event handlers.
  643. d116 3
  644. a118 2
  645.     if (fn == NULL) {
  646.     fn = XGetDefault(display, "mx", "font");
  647. a119 125
  648.     if (fn != NULL) {
  649.     info.fontPtr = XLoadQueryFont(display, fn);
  650.     if (info.fontPtr != NULL) {
  651.         Sx_SetDefaultFont(info.fontPtr);
  652.     } else {
  653.         info.fontPtr = Sx_GetDefaultFont(display);
  654.     }
  655.     } else {
  656.     info.fontPtr = Sx_GetDefaultFont(display);
  657.     }
  658.     info.file = Mx_FileLoad(info.name);
  659.     if (info.file == NULL) {
  660.     if (errno != ENOENT) {
  661.         char msg[100];
  662.         int result;
  663.         sprintf(msg, "Mx couldn't read\n\"%s\":\n%s.",
  664.             info.name, strerror(errno));
  665.         result = Sx_Notify(display, DefaultRootWindow(display), -1, -1, 0,
  666.         msg, info.fontPtr, 1, "Make a new file", "Quit", NULL);
  667.         if (result == 1) {
  668.         exit(0);
  669.         }
  670.     }
  671.     info.file = Mx_FileLoad((char *) NULL);
  672.     }
  673.     info.flags = MX_UNDO|MX_DELETE;
  674.     if (fg == NULL) {
  675.     fg = XGetDefault(display, "mx", "foreground");
  676.     }
  677.     info.foreground = MainGetColor(display, fg,
  678.         BlackPixel(display, DefaultScreen(display)));
  679.     if (bg == NULL) {
  680.     bg = XGetDefault(display, "mx", "background");
  681.     }
  682.     info.background = MainGetColor(display, bg,
  683.         WhitePixel(display, DefaultScreen(display)));
  684.     if (border == NULL) {
  685.     border = XGetDefault(display, "mx", "borderColor");
  686.     }
  687.     info.border = MainGetColor(display, border,
  688.         BlackPixel(display, DefaultScreen(display)));
  689.     if (sbFg == NULL) {
  690.     sbFg = XGetDefault(display, "mx", "scrollbar.foreground");
  691.     }
  692.     info.sbForeground = MainGetColor(display, sbFg, info.foreground);
  693.     if (sbBg == NULL) {
  694.     sbBg = XGetDefault(display, "mx", "scrollbar.background");
  695.     }
  696.     info.sbBackground = MainGetColor(display, sbBg, info.background);
  697.     if (sbEl == NULL) {
  698.     sbEl = XGetDefault(display, "mx", "scrollbar.elevator");
  699.     }
  700.     info.sbElevator = MainGetColor(display, sbEl, info.background);
  701.     if (titleFg == NULL) {
  702.     titleFg = XGetDefault(display, "mx", "title.foreground");
  703.     }
  704.     info.titleForeground = MainGetColor(display, titleFg, info.foreground);
  705.     if (titleBg == NULL) {
  706.     titleBg = XGetDefault(display, "mx", "title.background");
  707.     }
  708.     info.titleBackground = MainGetColor(display, titleBg, info.background);
  709.     if (titleStripe == NULL) {
  710.     titleStripe = XGetDefault(display, "mx", "title.stripe");
  711.     }
  712.     info.titleStripe = MainGetColor(display, titleStripe, info.foreground);
  713.  
  714.     if (geometry == NULL) {
  715.     geometry = "=80x30";
  716.     }
  717.     window = MxCreateWindow(display, geometry, info.fontPtr,
  718.         4*Sx_DefaultHeight(display, info.fontPtr) + 5,
  719.         info.foreground, info.background, &info.width,
  720.         &info.height);
  721.     if (Mx_Make(display, window, &info, interp) != TCL_OK) {
  722.     fprintf(stderr, "Mx quitting: %s.\n", interp->result);
  723.  
  724.     /*
  725.      * Go immediately to the main command loop, in order to wait
  726.      * for the window to be deleted gracefully before exiting.
  727.      */
  728.  
  729.     exitValue = 1;
  730.     goto mainLoop;
  731.     }
  732.     mxwPtr = MxGetMxWindow(display, window);
  733.     mxwPtr->fileInfoPtr->lastMod = MxLastMod(info.name);
  734.  
  735.     /*
  736.      * If a line number or search string was given, set the view at
  737.      * the correct line number.  Don't forget:  users number lines from
  738.      * 1, but we number from 0.
  739.      */
  740.  
  741.     if (lineNumber != -1) {
  742.     Mx_Position first, last, eof;
  743.  
  744.     eof = Mx_EndOfFile(mxwPtr->fileInfoPtr->file);
  745.     if (lineNumber == -2) {
  746.         first = eof;
  747.     } else {
  748.         first.lineIndex = lineNumber;
  749.         first.charIndex = 0;
  750.         if (MX_POS_LESS(last, eof)) {
  751.         first = Mx_Offset(mxwPtr->fileInfoPtr->file, first, -1);
  752.         } else {
  753.         first = eof;
  754.         }
  755.     }
  756.     first.charIndex = 0;
  757.     MxSelectionSet(mxwPtr, first, first);
  758.     MxGetInWindow(mxwPtr, first, mxwPtr->heightLines/2, 0);
  759.     } else if (searchString != NULL) {
  760.     Mx_Position first, last;
  761.  
  762.     if (!Mx_SearchPattern(info.file, Mx_ZeroPosition,
  763.         Mx_EndOfFile(info.file), searchString, &first, &last)) {
  764.         (void) Sx_Notify(display, window, -1, -1, 0,
  765.             "Couldn't find matching pattern.", mxwPtr->fontPtr, 1,
  766.             "Continue", NULL);
  767.     } else {
  768.         MxSelectionSet(mxwPtr, first, last);
  769.         MxGetInWindow(mxwPtr, first, mxwPtr->heightLines/2, 0);
  770.     }
  771.     }
  772.     XMapRaised(display, window);
  773. d130 1
  774. a130 1
  775.     XNextEvent(display, &event);
  776. d142 1
  777. a142 1
  778.         exit(exitValue);
  779. a150 55
  780.  * MainGetColor --
  781.  *
  782.  *    This local procedure is used to parse a color spec and return
  783.  *    a matching color.
  784.  *
  785.  * Results:
  786.  *    The return value is a color value to use for the given spec.
  787.  *    If the color couldn't be found, then the default value is
  788.  *    returned.  If the display isn't a color display and the color
  789.  *    isn't black or white, then the default is returned.
  790.  *
  791.  * Side effects:
  792.  *    None.
  793.  *
  794.  *----------------------------------------------------------------------
  795.  */
  796.  
  797. static unsigned long
  798. MainGetColor(display, colorName, defPixel)
  799.     Display *display;        /* Connection to X server. */
  800.     char *colorName;        /* Description of color, or NULL. */
  801.     unsigned long defPixel;    /* Default to use if colorName is NULL or
  802.                  * can't be found. */
  803. {
  804.     XColor color;
  805.  
  806.     if (colorName == NULL) {
  807.     return defPixel;
  808.     }
  809.     if (DisplayCells(display, DefaultScreen(display)) <= 2) {
  810.     if ((strcmp(colorName, "black") == 0)
  811.         || (strcmp(colorName, "Black") == 0)) {
  812.         return BlackPixel(display, DefaultScreen(display));
  813.     } else if ((strcmp(colorName, "white") == 0)
  814.         || (strcmp(colorName, "White") == 0)) {
  815.         return WhitePixel(display, DefaultScreen(display));
  816.     } else {
  817.         return defPixel;
  818.     }
  819.     }
  820.     if (XParseColor(display,
  821.         DefaultColormap(display, DefaultScreen(display)), colorName,
  822.         &color) == 0) {
  823.     return defPixel;
  824.     }
  825.     if (XAllocColor(display, 
  826.         DefaultColormap(display, DefaultScreen(display)), &color) == 0) {
  827.     return defPixel;
  828.     }
  829.     return color.pixel;
  830. }
  831.  
  832. /*
  833.  *----------------------------------------------------------------------
  834.  *
  835. d166 1
  836. a166 1
  837. static int
  838. @
  839.  
  840.  
  841. 1.20
  842. log
  843. @Comment clean-up.
  844. @
  845. text
  846. @d19 1
  847. a19 1
  848. static char rcsid[] = "$Header: /a/newcmds/mx/RCS/mx.c,v 1.19 89/05/19 10:33:13 ouster Exp Locker: ouster $ SPRITE (Berkeley)";
  849. d363 1
  850. @
  851.  
  852.  
  853. 1.19
  854. log
  855. @Clean up static definitions, use symbolic link for mxInt.h
  856. @
  857. text
  858. @d2 1
  859. a2 1
  860.  * main.c --
  861. d19 1
  862. a19 1
  863. static char rcsid[] = "$Header: /a/newcmds/mx/RCS/main.c,v 1.18 89/01/07 12:20:31 ouster Exp Locker: ouster $ SPRITE (Berkeley)";
  864. @
  865.  
  866.  
  867. 1.18
  868. log
  869. @Better color support.
  870. @
  871. text
  872. @d19 1
  873. a19 1
  874. static char rcsid[] = "$Header: /a/newcmds/mx/RCS/main.c,v 1.17 88/12/23 14:55:16 ouster Exp Locker: ouster $ SPRITE (Berkeley)";
  875. d32 1
  876. a32 1
  877. #include </sprite/src/lib/mx/mxInt.h>
  878. d44 2
  879. a45 2
  880. extern unsigned long    MainGetColor();
  881. extern int        MainSignalProc();
  882. d502 2
  883. a503 1
  884.     
  885. @
  886.  
  887.  
  888. 1.17
  889. log
  890. @Change to use /sprite/lib/mx as the library directory.
  891. @
  892. text
  893. @d19 1
  894. a19 1
  895. static char rcsid[] = "$Header: /a/newcmds/mx/RCS/main.c,v 1.16 88/10/03 09:23:14 ouster Exp Locker: ouster $ SPRITE (Berkeley)";
  896. d70 1
  897. d89 1
  898. d119 42
  899. d314 29
  900. d457 1
  901. a457 1
  902.     XColor hard, exact;
  903. d473 1
  904. a473 1
  905.     if (XAllocNamedColor(display,
  906. d475 1
  907. a475 1
  908.         &hard, &exact) == 0) {
  909. d478 5
  910. a482 1
  911.     return hard.pixel;
  912. @
  913.  
  914.  
  915. 1.16
  916. log
  917. @Changed file name.
  918. @
  919. text
  920. @d19 1
  921. a19 1
  922. static char rcsid[] = "$Header: mxMain.c,v 1.15 88/08/31 08:19:32 ouster Exp $ SPRITE (Berkeley)";
  923. d206 1
  924. a206 1
  925.     sprintf(tutName, "%.80s/%s", HELPDIR, "tutorial1");
  926. @
  927.  
  928.  
  929. 1.15
  930. log
  931. @Wrong test of XAllocNamedColor return value.
  932. @
  933. text
  934. @d2 1
  935. a2 1
  936.  * mxMain.c --
  937. d19 1
  938. a19 1
  939. static char rcsid[] = "$Header: mxMain.c,v 1.14 88/08/20 15:49:50 ouster Exp $ SPRITE (Berkeley)";
  940. @
  941.  
  942.  
  943. 1.14
  944. log
  945. @On errors, wait for window to get cleaned up before exiting.
  946. @
  947. text
  948. @d19 1
  949. a19 1
  950. static char rcsid[] = "$Header: mxMain.c,v 1.13 88/07/18 13:45:14 ouster Exp $ SPRITE (Berkeley)";
  951. d402 1
  952. a402 1
  953.         &hard, &exact) != 0) {
  954. @
  955.  
  956.  
  957. 1.13
  958. log
  959. @Go back to using UNIX library procedures (wherever possible).
  960. @
  961. text
  962. @d19 1
  963. a19 1
  964. static char rcsid[] = "$Header: mxMain.c,v 1.12 88/04/20 17:23:41 ouster Exp $ SPRITE (Berkeley)";
  965. d76 1
  966. d280 8
  967. a287 1
  968.     exit(1);
  969. d335 2
  970. a336 1
  971.     
  972. d351 1
  973. a351 1
  974.         exit(0);
  975. @
  976.  
  977.  
  978. 1.12
  979. log
  980. @Major Tcl revision:  put tcl_Result into individual interpreters,
  981. use {} instead of (), etc.
  982. @
  983. text
  984. @d19 1
  985. a19 1
  986. static char rcsid[] = "$Header: mxMain.c,v 1.11 88/04/01 12:58:45 ouster Exp $ SPRITE (Berkeley)";
  987. a23 1
  988. #undef Boolean
  989. d25 2
  990. a26 6
  991. #include <sprite.h>
  992. #include <char.h>
  993. #include <cvt.h>
  994. #include <io.h>
  995. #include "mx.h"
  996. #include "mxInt.h"
  997. d28 3
  998. a30 2
  999. #include <sig.h>
  1000. #include <status.h>
  1001. d32 1
  1002. a32 2
  1003. #include <sx.h>
  1004. #include <tcl.h>
  1005. d73 2
  1006. a74 2
  1007.     Sig_Action old, action;
  1008.     Boolean debug;
  1009. d89 1
  1010. a89 1
  1011.     debug = FALSE;
  1012. d94 1
  1013. a94 1
  1014.     } else if (String_Compare(argv[i], "-fn") == 0) {
  1015. d98 1
  1016. a98 1
  1017.         Io_PrintStream(io_StdErr,
  1018. d101 1
  1019. a101 1
  1020.         Proc_Exit(1);
  1021. d104 1
  1022. a104 1
  1023.     } else if (String_Compare(argv[i], "-fg") == 0) {
  1024. d110 1
  1025. a110 1
  1026.     } else if (String_Compare(argv[i], "-bg") == 0) {
  1027. d116 1
  1028. a116 1
  1029.     } else if (String_Compare(argv[i], "-t") == 0) {
  1030. d127 2
  1031. a128 2
  1032.         Io_PrintStream(io_StdErr, "%s\n", interp->result);
  1033.         Proc_Exit(1);
  1034. d131 3
  1035. a133 3
  1036.     } else if (String_Compare(argv[i], "-D") == 0) {
  1037.         debug = TRUE;
  1038.     } else if (String_Compare(argv[i], "-s") == 0) {
  1039. d144 1
  1040. a144 1
  1041.         Io_ScanString(argv[i], "%d", &signalPid);
  1042. d146 1
  1043. a146 1
  1044.         Io_PrintStream(io_StdErr, "Mx: switch \"%s\" isn't legal.\n",
  1045. d148 2
  1046. a149 2
  1047.         Proc_Exit(1);
  1048.     } else if (String_FindChar(argv[i], ':') != NULL) {
  1049. d155 1
  1050. a155 1
  1051.         } else if (!Char_IsDigit(argv[i][1])) {
  1052. d163 1
  1053. a163 1
  1054.         result = Cvt_AtoI(argv[i] + 1, 10, &lineNumber);
  1055. d166 1
  1056. a166 1
  1057.             Io_PrintStream(io_StdErr,
  1058. d168 1
  1059. a168 1
  1060.             Proc_Exit(1);
  1061. d183 2
  1062. a184 2
  1063.         Io_PrintStream(io_StdErr, "Mx couldn't open the display.\n");
  1064.         Io_PrintStream(io_StdErr,
  1065. d187 1
  1066. a187 1
  1067.         Io_PrintStream(io_StdErr, "Mx couldn't open display %s.\n",
  1068. d190 1
  1069. a190 1
  1070.     Proc_Exit(1);
  1071. d205 1
  1072. a205 1
  1073.     Io_PrintString(tutName, "%.80s/%s", HELPDIR, "tutorial1");
  1074. d212 11
  1075. a222 8
  1076.     action.action = SIG_HANDLE_ACTION;
  1077.     action.handler = MainSignalProc;
  1078.     action.sigHoldMask = 0;
  1079.     Sig_SetAction(SIG_INTERRUPT, &action, &old);
  1080.     Sig_SetAction(SIG_ARITH_FAULT, &action, &old);
  1081.     Sig_SetAction(SIG_ILL_INST, &action, &old);
  1082.     Sig_SetAction(SIG_ADDR_FAULT, &action, &old);
  1083.     Sig_SetAction(SIG_TERM, &action, &old);
  1084. d245 1
  1085. a245 1
  1086.     if (stat_LastError != FS_FILE_NOT_FOUND) {
  1087. d248 2
  1088. a249 2
  1089.         Io_PrintString(msg, "Mx couldn't read\n\"%s\":\n%s.",
  1090.             info.name, Stat_GetMsg(stat_LastError));
  1091. d251 1
  1092. a251 1
  1093.         msg, info.fontPtr, TRUE, "Make a new file", "Quit", NULL);
  1094. d253 1
  1095. a253 1
  1096.         Proc_Exit(0);
  1097. d278 2
  1098. a279 2
  1099.     Io_PrintStream(io_StdErr, "Mx quitting: %s.\n", interp->result);
  1100.     Proc_Exit(1);
  1101. d306 1
  1102. a306 1
  1103.     MxGetInWindow(mxwPtr, first, mxwPtr->heightLines/2, FALSE);
  1104. d313 1
  1105. a313 1
  1106.             "Couldn't find matching pattern.", mxwPtr->fontPtr, TRUE,
  1107. d317 1
  1108. a317 1
  1109.         MxGetInWindow(mxwPtr, first, mxwPtr->heightLines/2, FALSE);
  1110. d328 1
  1111. a328 1
  1112.     while (TRUE) {
  1113. d337 1
  1114. a337 1
  1115.         Sig_Send(SIG_INTERRUPT, signalPid, FALSE);
  1116. d342 1
  1117. a342 1
  1118.         Proc_Exit(0);
  1119. d381 2
  1120. a382 2
  1121.     if ((String_Compare(colorName, "black") == 0)
  1122.         || (String_Compare(colorName, "Black") == 0)) {
  1123. d384 2
  1124. a385 2
  1125.     } else if ((String_Compare(colorName, "white") == 0)
  1126.         || (String_Compare(colorName, "White") == 0)) {
  1127. d421 2
  1128. a422 2
  1129.     static Sig_Action action = {SIG_DEFAULT_ACTION, (int (*)()) NULL, 0};
  1130.     Sig_Action old;
  1131. d424 1
  1132. a424 1
  1133.     Sig_SetAction(sigNum, &action, &old);
  1134. d426 1
  1135. a426 1
  1136.     Sig_Send(sigNum, PROC_MY_PID, FALSE);
  1137. @
  1138.  
  1139.  
  1140. 1.11
  1141. log
  1142. @Change X defaults to not be capitalized.
  1143. @
  1144. text
  1145. @d19 1
  1146. a19 1
  1147. static char rcsid[] = "$Header: mxMain.c,v 1.10 88/03/31 09:21:44 ouster Exp $ SPRITE (Berkeley)";
  1148. d81 3
  1149. d95 1
  1150. d128 1
  1151. a128 1
  1152.         Tcl_Return((char *) NULL, TCL_STATIC);
  1153. d130 1
  1154. a130 1
  1155.             &searchString);
  1156. d132 1
  1157. a132 1
  1158.         Io_PrintStream(io_StdErr, "%s\n", tcl_Result);
  1159. d279 2
  1160. a280 2
  1161.     if (Mx_Make(display, window, &info) != TCL_OK) {
  1162.     Io_PrintStream(io_StdErr, "Mx quitting: %s.\n", tcl_Result);
  1163. @
  1164.  
  1165.  
  1166. 1.10
  1167. log
  1168. @Use correct Tcl interface when calling Mx_GetTag.
  1169. @
  1170. text
  1171. @d19 1
  1172. a19 1
  1173. static char rcsid[] = "$Header: mxMain.c,v 1.9 88/03/16 17:30:43 ouster Exp $ SPRITE (Berkeley)";
  1174. d196 1
  1175. a196 1
  1176.     geometry = XGetDefault(display, "mx", "WindowGeometry");
  1177. d229 1
  1178. a229 1
  1179.     fn = XGetDefault(display, "mx", "Font");
  1180. d258 1
  1181. a258 1
  1182.     fg = XGetDefault(display, "mx", "Foreground");
  1183. d263 1
  1184. a263 1
  1185.     bg = XGetDefault(display, "mx", "Background");
  1186. @
  1187.  
  1188.  
  1189. 1.9
  1190. log
  1191. @Massive revision to switch over to using Tcl.
  1192. @
  1193. text
  1194. @d19 1
  1195. a19 1
  1196. static char rcsid[] = "$Header: mxMain.c,v 1.2 88/02/20 13:23:14 ouster Exp $ SPRITE (Berkeley)";
  1197. d124 1
  1198. d127 2
  1199. a128 2
  1200.         if (result != NULL) {
  1201.         Io_PrintStream(io_StdErr, "%s\n", result);
  1202. @
  1203.  
  1204.  
  1205. 1.8
  1206. log
  1207. @Take out environment hack.
  1208. @
  1209. text
  1210. @d8 1
  1211. a8 1
  1212.  * Copyright (C) 1986 Regents of the University of California.
  1213. d19 1
  1214. a19 1
  1215. static char rcsid[] = "$Header: mxMain.c,v 1.7 88/01/05 19:22:22 nelson Exp $ SPRITE (Berkeley)";
  1216. d26 4
  1217. a29 4
  1218. #include "sprite.h"
  1219. #include "char.h"
  1220. #include "cvt.h"
  1221. #include "io.h"
  1222. d32 6
  1223. a37 5
  1224. #include "proc.h"
  1225. #include "sig.h"
  1226. #include "status.h"
  1227. #include "string.h"
  1228. #include "sx.h"
  1229. d118 1
  1230. a118 1
  1231.         char *result;
  1232. d274 2
  1233. a275 1
  1234.     if (!Mx_Make(display, window, &info)) {
  1235. @
  1236.  
  1237.  
  1238. 1.7
  1239. log
  1240. @Changed the Sig_Send for Mike's hack to send to the process only, not a
  1241. family.
  1242. @
  1243. text
  1244. @d19 1
  1245. a19 1
  1246. static char rcsid[] = "$Header: mxMain.c,v 1.6 88/01/04 15:30:04 ouster Exp $ SPRITE (Berkeley)";
  1247. a79 8
  1248.  
  1249.     /*
  1250.      * The lines below are a temporary hack until the environment stuff
  1251.      * gets straightened out.
  1252.      */
  1253.  
  1254.     extern char **environ;
  1255.     environ = 0;
  1256. @
  1257.  
  1258.  
  1259. 1.6
  1260. log
  1261. @Special hack for Mike.
  1262. @
  1263. text
  1264. @d19 1
  1265. a19 1
  1266. static char rcsid[] = "$Header: mxMain.c,v 1.5 88/01/03 15:21:42 ouster Exp $ SPRITE (Berkeley)";
  1267. d340 1
  1268. a340 1
  1269.         Sig_Send(SIG_INTERRUPT, signalPid, TRUE);
  1270. @
  1271.  
  1272.  
  1273. 1.5
  1274. log
  1275. @Temporary hack to make environments work.
  1276. @
  1277. text
  1278. @d19 1
  1279. a19 1
  1280. static char rcsid[] = "$Header: mxMain.c,v 1.4 87/11/28 13:25:43 ouster Exp $ SPRITE (Berkeley)";
  1281. d79 1
  1282. d140 12
  1283. d334 9
  1284. @
  1285.  
  1286.  
  1287. 1.4
  1288. log
  1289. @Don't tie server-synchronization to -D flag:  it's too slow.
  1290. @
  1291. text
  1292. @d19 1
  1293. a19 1
  1294. static char rcsid[] = "$Header: mxMain.c,v 1.3 87/10/23 14:16:32 deboor Exp $ SPRITE (Berkeley)";
  1295. d79 8
  1296. @
  1297.  
  1298.  
  1299. 1.3
  1300. log
  1301. @Adapted to new XGetDefault
  1302. @
  1303. text
  1304. @d19 1
  1305. a19 1
  1306. static char rcsid[] = "$Header: mxMain.c,v 1.2 87/08/24 10:55:33 ouster Exp $ SPRITE (Berkeley)";
  1307. d178 1
  1308. a178 3
  1309.     if (debug) {
  1310.     XSynchronize(display, True);
  1311.     }
  1312. @
  1313.  
  1314.  
  1315. 1.2
  1316. log
  1317. @Lint.
  1318. @
  1319. text
  1320. @d19 1
  1321. a19 1
  1322. static char rcsid[] = "$Header: mxMain.c,v 1.1 87/08/21 10:33:58 ouster Exp $ SPRITE (Berkeley)";
  1323. d183 1
  1324. a183 1
  1325.     geometry = XGetDefault("mx", "WindowGeometry");
  1326. d216 1
  1327. a216 1
  1328.     fn = XGetDefault("mx", "Font");
  1329. d245 1
  1330. a245 1
  1331.     fg = XGetDefault("mx", "Foreground");
  1332. d250 1
  1333. a250 1
  1334.     bg = XGetDefault("mx", "Background");
  1335. @
  1336.  
  1337.  
  1338. 1.1
  1339. log
  1340. @Initial revision
  1341. @
  1342. text
  1343. @d19 1
  1344. a19 1
  1345. static char rcsid[] = "$Header: mxMain.c,v 1.6 87/08/03 11:05:39 ouster Exp $ SPRITE (Berkeley)";
  1346. d75 1
  1347. a75 1
  1348.     int i, lineNumber, flags;
  1349. @
  1350.